home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / FERROR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  504 b   |  20 lines

  1. /* ferror.c */
  2. #include <stdio.h>
  3. char buffer[81] = "This will not be written";
  4. main()
  5. {
  6.      FILE *infile;
  7.         /* Open the file "c:\autoexec.bat". Note the two '\' */
  8.     if ((infile = fopen("c:\\autoexec.bat", "r")) == NULL)
  9.     {
  10.         perror ("fopen failed.\n");
  11.         exit(0);
  12.     }
  13.     fprintf(infile, "%s\n", buffer);
  14.     if (ferror(infile) != 0)    /* Check for error */
  15.     {
  16.         printf("Error detected\n");
  17.         clearerr(infile);       /* Now clear the error */
  18.         printf("Error cleared\n");
  19.     }
  20. }